package terra.network.packet.server;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;

public class ItemInfo extends Packet {

	public static final byte INVENTORY = 0;
	public static final byte WEARED = 1;
	
	public int id;
	public byte type;
	public int oId;
	public int count;
	public byte position;
	public byte container = 0;

	public ItemInfo(int objectId, int id, int count, byte pos, byte container) {
		oId = objectId;
		this.id = id;
		this.count = count;
		position = pos;
		this.container = container;
	}
	
	public ItemInfo() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer();
		buf.writeByte(getId());
		buf.writeInt(oId);		
		buf.writeInt(id);
		buf.writeInt(count);
		buf.writeByte(type);	
		buf.writeByte(container);	
		buf.writeByte(position);	
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		oId = buf.readInt();
		id = buf.readInt();
		count = buf.readInt();
		type = buf.readByte();
		container = buf.readByte();
		position = buf.readByte();
		return this;
	}

	@Override
	public int getLength() {
		return 16;
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getId() {
		return 15;
	}
	
	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}
	
	public String toString(){
		return "ItemInfo: id="+id+"  type="+type+"  oId="+oId+"   count="+count+"   pos=" +position+"   container="+container+"";
	}

}
